<?php
/*
 * $Author ：PHPYUN开发团队
 *
 * 官网: http://www.phpyun.com
 *
 * 版权所有 2009-2018 宿迁鑫潮信息技术有限公司，并保留所有权利。
 *
 * 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class resume_controller extends wxapp_controller{
    function list_action(){//简历列表
        $_POST=$this->post_trim($_POST);
        $where = "a.`status`='1' AND a.`r_status`='1' AND a.`defaults`='1' and a.`open`='1' and a.`height_status`='0'";
        $page=$_POST['page'];
        $limit=$_POST['limit'];
        $time=time();
        $CacheArr=$this->MODEL('cache')->GetCache(array('user','city','job'));
        if($_POST['exp']){
            $where.=" AND a.`exp`='".$_POST['exp']."'";
        }
        $citywhere = "1";
        if($_POST['provinceid']){
            $citywhere .= " AND `provinceid` = '".$_POST['provinceid']."'";
        }
        if($_POST['cityid']){
            $citywhere .= " AND `cityid` = '".$_POST['cityid']."'";
        }
        if($_POST['three_cityid']){
            $citywhere .= " AND `three_cityid` = '".$_POST['three_cityid']."'";
        }
        $jobwhere = "1";
        if($_POST['job1']){
            $jobwhere.=" AND `job1`= '".$_POST['job1']."'";
        }
        if($_POST['job1_son']){
            $jobwhere.=" AND `job1_son`= '".$_POST['job1_son']."'";
        }
        if($_POST['job_post']){
            $jobwhere.=" AND `job_post`= '".$_POST['job_post']."'";
        }
        if ($_POST['keyword']){
            $keyword=$this->stringfilter($_POST['keyword']);
            $where1[]="a.`name` LIKE '%$keyword%'";
            $where1[]="a.`uname` LIKE '%$keyword%'";
            $cityid=array();
            foreach($CacheArr['city_name'] as $k=>$v){
                if(strpos($v,$keyword)!==false){
                    $cityid[]=$k;
                }
            }
            //匹配城市
            if(!empty($cityid)){
                $ckwhere ='`cityid` IN ('.pylode(',', $cityid).') or `three_cityid` IN ('.pylode(',', $cityid).')';
                $cityresume = $this->obj->DB_select_all('resume_cityclass',$ckwhere);
                if($cityresume){
                    foreach ($cityresume as $k=>$v){
                        $where1[]=' `a.id`='.$v['eid'];
                    }
                }
            }
            $where.=" AND (".@implode(" or ",$where1).")";
        }
        $order = " order by a.`lastupdate` desc";
        if($page){//分页
            $pagenav=($page-1)*$limit;
            $resumelimit=" limit $pagenav,$limit";
        }else{
            $resumelimit=" limit $limit";
        }
        $pagewhere = "";$joinwhere = "";
        if($citywhere!="1"){
            $pagewhere.=" ,(select `eid` from `".$this->def."resume_cityclass` where ".$citywhere." group by `eid`) b";
            $joinwhere .= " a.`id`=b.`eid` and ";
        }
        if($jobwhere!="1"){
            $pagewhere.=" ,(select `eid` from `".$this->def."resume_jobclass` where ".$jobwhere." group by `eid`) c";
            $joinwhere .= " a.`id`=c.`eid` and ";
        }
        $select="a.`id`,a.`uid`,a.`name`,a.`hy`,a.`job_classid`,a.`city_classid`,a.`jobstatus`,a.`type`,a.`report`,a.`lastupdate`,a.`rec`,a.`top`,a.`topdate`,a.`rec_resume`,a.`ctime`,a.`uname`,a.`idcard_status`,a.`minsalary`,a.`maxsalary`,a.`topdate`";
        if($pagewhere!=""){
            $sql = "select ".$select." from `".$this->def."resume_expect` a ".$pagewhere." where ".$joinwhere.$where.$order.$resumelimit;
        }else{
            $sql = "select ".$select." from `".$this->def."resume_expect` a where ".$where.$order.$resumelimit;
        }
        $rows=$this->obj->DB_query_all($sql,'all');
        if ($_POST['uid']){
            //已下载
            $down=$this->obj->DB_select_all('down_resume','comid='.$_POST['uid'].'','eid');
            foreach ($down as $v){
                $eid[]=$v['eid'];
            }
        }
        if($rows&&is_array($rows)){
            include(CONFIG_PATH."db.data.php");
            if ($page==1){
                $where.=' and a.`topdate`>"'.$time.'"';
                if($pagewhere!=""){
                    $sql = "select ".$select." from `".$this->def."resume_expect` a ".$pagewhere." where ".$joinwhere.$where.' ORDER BY rand() limit 5';
                }else{
                    $sql = "select ".$select." from `".$this->def."resume_expect` a where ".$where.' ORDER BY rand() limit 5';
                }
                $topresume=$this->obj->DB_query_all($sql,'all');
                if ($topresume){
                    foreach($rows as $k=>$v){
                        foreach ($topresume as $val){
                            if($v['id']==$val['id']){
                                unset($rows[$k]);
                            }
                        }
                    }
                    foreach ($topresume as $v){
                        array_unshift($rows,$v);
                    }
                }
            }
            foreach ($rows as $v){
                $uids[]=$v['uid'];
            }
            $resume=$this->obj->DB_select_all("resume","`uid` in(".pylode(',', $uids).")","uid,name,nametype,tag,sex,moblie_status,edu,exp,resume_photo,phototype,birthday");
            foreach($rows as $key=>$v){
                foreach ($resume as $val){
                    if ($v['uid']==$val['uid']){
                        if($val['birthday']){
                            $birthday=@explode('-',$val['birthday']);
                            $list[$key]['age']=date("Y")-$birthday[0];
                        }
                        $list[$key]['edu_n']=$CacheArr['userclass_name'][$val['edu']];
                        $list[$key]['exp_n']=$CacheArr['userclass_name'][$val['exp']];
                        if($val['sex']==152){
                            $val['sex']='1';
                        }elseif ($val['sex']==153){
                            $val['sex']='2';
                        }
                        $list[$key]['sex_n']=$arr_data['sex'][$val['sex']];
                        if($this->config['user_pic']==1 || !$this->config['user_pic']){
                            if($val['resume_photo'] && $val['phototype']!=1&&(file_exists(str_replace('../',APP_PATH,'.'.$val['resume_photo']))||file_exists(str_replace('./',APP_PATH,$val['resume_photo'])))){
                                $list[$key]['photo_n']=str_replace("./",$this->config['sy_weburl']."/",$val['resume_photo']);
                            }else{
                                if($val['sex']==1){
                                    $list[$key]['photo_n']=$this->config['sy_weburl']."/".$this->config['sy_member_icon'];
                                }else{
                                    $list[$key]['photo_n']=$this->config['sy_weburl']."/".$this->config['sy_member_iconv'];
                                }
                            }
                        }elseif($this->config['user_pic']==2){
                            if($val['resume_photo']&&(file_exists(str_replace('../',APP_PATH,'.'.$val['resume_photo']))||file_exists(str_replace('./',APP_PATH,$val['resume_photo'])))){
                                $list[$key]['photo_n']=str_replace("./",$this->config['sy_weburl']."/",$val['resume_photo']);
                            }else{
                                if($val['sex']==1){
                                    $list[$key]['photo_n']=$this->config['sy_weburl']."/".$this->config['sy_member_icon'];
                                }else{
                                    $list[$key]['photo_n']=$this->config['sy_weburl']."/".$this->config['sy_member_iconv'];
                                }
                            }
                        }elseif($this->config['user_pic']==3){
                            if($val['sex']==1){
                                $list[$key]['photo_n']=$this->config['sy_weburl']."/".$this->config['sy_member_icon'];
                            }else{
                                $list[$key]['photo_n']=$this->config['sy_weburl']."/".$this->config['sy_member_iconv'];
                            }
                        }
                        //名称显示处理
                        if ($down){
                            if (in_array($v['id'], $eid)){
                                $list[$key]['name'] = mb_substr($val['name'], 0, 6, "utf-8");
                            }
                        }else{
                            if($this->config['user_name']==1 || !$this->config['user_name']){
                                if($val['nametype']==3){
                                    if($val['sex']==1){
                                        $list[$key]['name'] = mb_substr($val['name'],0,1,'utf-8')."先生";
                                    }else{
                                        $list[$key]['name'] = mb_substr($val['name'],0,1,'utf-8')."女士";
                                    }
                                }elseif($val['nametype']==2){
                                    $list[$key]['name'] = "NO.".$v['id'];
                                }else{
                                    $list[$key]['name'] =  mb_substr($val['name'], 0, 6, "utf-8");
                                }
                            }elseif($this->config['user_name']==3){
                                if($val['sex']==1){
                                    $list[$key]['name'] = mb_substr($val['name'],0,1,'utf-8')."先生";
                                }else{
                                    $list[$key]['name'] = mb_substr($val['name'],0,1,'utf-8')."女士";
                                }
                            }elseif($this->config['user_name']==2){
                                $list[$key]['name'] = "NO.".$v['id'];
                            }elseif($this->config['user_name']==4){
                                $list[$key]['name'] = mb_substr($val['name'], 0, 6, "utf-8");
                            }
                        }
                    }
                }
                $kjob_classid=@explode(",",$v['job_classid']);
                $kjob_classid=array_unique($kjob_classid);
                $jobname=array();
                if(is_array($kjob_classid)){
                    foreach($kjob_classid as $val){
                        if($val!=''){
                            $jobname[]=$CacheArr['job_name'][$val];
                        }
                    }
                }
                $list[$key]['job_n']=$jobname;
                
                $kcity_classid=@explode(",",$v['city_classid']);
                $kcity_classid=array_unique($kcity_classid);
                $cityname=array();
                if(is_array($kcity_classid)){
                    foreach($kcity_classid as $val){
                        if($val!=''){
                            $cityname[]=$CacheArr['city_name'][$val];
                        }
                    }
                }
                $list[$key]['city']=mb_substr(implode(',', $cityname),0,14,"utf-8");
                if($v['minsalary']&&$v['maxsalary']){
                    $list[$key]['salary_n'] ="￥".$v['minsalary']."-".$v['maxsalary'];
                }elseif($v['minsalary']){
                    $list[$key]['salary_n'] ="￥".$v['minsalary']."以上";
                }else{
                    $list[$key]['salary_n'] ="面议";
                }
                $ltime=$v['lastupdate'];
                //今天开始时间戳
                $beginToday=mktime(0,0,0,date('m'),date('d'),date('Y'));
                //昨天开始时间戳
                $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
                //一周内时间戳
                $week=strtotime(date("Y-m-d",strtotime("-1 week")));
                if($ltime>$week && $ltime<$beginYesterday){
                    $list[$key]['lastupdate_n'] ="一周内";
                }elseif($ltime>$beginYesterday && $ltime<$beginToday){
                    $list[$key]['lastupdate_n'] ="昨天";
                }elseif($ltime>$beginToday){
                    $list[$key]['lastupdate_n'] = date("H:i",$ltime);
                    $list[$key]['redtime'] =1;
                }else{
                    $list[$key]['lastupdate_n'] = date("Y-m-d",$ltime);
                }
                
                $list[$key]['id']			=$v['id'];
                $list[$key]['rec_resume']	=$v['rec_resume'];
                if ($v['topdate']>$time){
                    $list[$key]['topresume']=1;
                }
            }
            foreach($list as $k=>$v){
                if(is_array($v)){
                    foreach($v as $key=>$val){
                        $list[$k][$key]=isset($val)?$val:'';
                    }
                }else{
                    $list[$k]=isset($v)?$v:'';
                }
            }
            $data['error']=1;
            $data['list']=count($list)?$list:array();
        }else{
            $data['error']=2;
            //$data['sql']=$sql;
        }
        echo json_encode($data);die;
    }
    function show_action(){//简历内容页
        $id=(int)$_POST['id'];
        $comid=(int)$_POST['comid'];
        if(!$id && !$comid){
            $data['error']=3;
            echo json_encode($data);die;
        }
        $where="b.`id`='".$id."' and a.`uid`=b.`uid`";
        $rows=$this->obj->DB_select_alls("resume","resume_expect",$where,"a.uid,a.name,a.sex,a.birthday,a.marriage,a.height,a.living,a.domicile,a.nationality,a.weight,a.edu,a.exp,b.provinceid,b.cityid,b.three_cityid,b.salary,b.type,b.hits,b.lastupdate,b.doc,a.idcard_pic,a.photo,a.resume_photo,a.description,a.address,a.homepage,a.email,a.telphone,a.idcard,b.hy,b.job_classid,b.report,b.id,b.integrity,b.jobstatus,a.idcard_status,b.avghour,a.tag,b.phototype,a.wxewm,b.lastupdate,b.minsalary,b.maxsalary,b.city_classid,a.nametype");
        $row=$rows[0];
        if(is_array($row)){
            $ResumeM=$this->MODEL('resume');
            $ResumeM->AddExpectHits($id);
            $data['talent_pool']=0;
            $data['userid_msg']=0;
            //简历浏览记录
            if($comid!=$row['uid']){
                //查看的用户是企业，记录相关信息
                $company=$this->obj->DB_select_once("company","`uid`='".$comid."'",'`uid`');
                if ($company){
                    $look_resume=$this->obj->DB_select_once("look_resume","`com_id`='".$comid."' and `resume_id`='".$row['id']."'");
                    if(!empty($look_resume)){
                        $this->obj->DB_update_all("look_resume","`datetime`='".time()."'","`com_id`='".$comid."' and `resume_id`='".$row['id']."'");
                    }else{
                        $value.="`uid`='".$row['uid']."',";
                        $value.="`resume_id`='".$row['id']."',";
                        $value.="`com_id`='".$comid."',";
                        $value.="`datetime`='".time()."'";
                        $this->obj->DB_insert_once("look_resume",$value);
                    }
                    $jobid=(int)$_POST['jobid'];
                    $userid_msg=$this->obj->DB_select_once("userid_msg","`fid`='".$comid."' and `uid`='".$row['uid']."' and `jobid`='".$jobid."'");
                    if(!empty($userid_msg)){
                        $data['userid_msg']=1;
                    }
                    
                    $talent_pool=$this->obj->DB_select_once("talent_pool","`cuid`='".$comid."' and `eid`='".$row['id']."'");
                    if(!empty($talent_pool)){
                        $data['talent_pool']=1;
                    }
                    
                    $userid_job=$this->obj->DB_select_once("userid_job","`com_id`='".$comid."' and `eid`='".$row['id']."'");
                    $comstatis = $this->obj->DB_select_once("company_statis","`uid`='".$comid."'","`rating`");
                    if(!empty($userid_job)&&in_array($comstatis['rating'], @explode(',', $this->config['com_look']))){//已投递简历并且免费查看联系方式
                        $data['m_status']=1;
                        $this->obj->update_once("userid_job",array("is_browse"=>"2"),array("com_id"=>$comid,"eid"=>$row['id'],"is_browse"=>"1"));
                    }
                    
                    $down=$this->obj->DB_select_once("down_resume","comid='".$comid."' and `eid`='".$row['id']."'");
                    if(!empty($down)){
                        $data['m_status']=1;
                    }
                }
            }else{
                $data['m_status']=1;
            }
            
            if($row['birthday']){
                $birthday=@explode('-',$row['birthday']);
                $data['info']['age']=date("Y")-$birthday[0].'岁';
            }
            if (!$data['info']['age']){
                $data['info']['age']='保密';
            }
            $description = preg_replace("/<([a-zA-Z] )[^>]*>/","<$1>",$row['description']);
            $description=$this->preghtml($description);
            $description = str_replace('<img','<p style="text-align:center;"><img',$description);
            $description=htmlspecialchars_decode($description);
            preg_match_all('<img(.*?)src=\"(.+?)\".*?>',$description,$res);
            if(!empty($res[2])){
                foreach($res[2] as $v){
                    if(strpos($v,'https:')===false && strpos($v,'http:')===false){
                        $imgurl=$v;
                        $description=str_replace($v,$this->config['sy_weburl'].$imgurl,$description);
                    }
                }
            }
            $description=str_replace("<>","",$description);
            include PLUS_PATH."/city.cache.php";
            include PLUS_PATH."/user.cache.php";
            include PLUS_PATH."/industry.cache.php";
            include PLUS_PATH."/job.cache.php";
            include(CONFIG_PATH."db.data.php");
            
            $data['info']['id']		=$row['id'];
            $data['info']['homepage']	=$row['homepage'];
            $data['info']['email']		=$row['email'];
            $data['info']['idcard_status']=$row['idcard_status'];
            $data['info']['telphone']	=$row['telphone'];
            $data['info']['telhome']	=$row['telhome'];
            $data['info']['idcard']		=$row['idcard']?$row['idcard']:"";
            $data['info']['uid']		=$row['uid'];
            $data['info']['name']		=$row['name'];
            $data['info']['living']		=$row['living'];
            $data['info']['sex']		=$row['sex'];
            $data['info']['edu']		=$row['edu'];
            $data['info']['exp']		=$row['exp'];
            $data['info']['provinceid']	=$row['provinceid'];
            $data['info']['cityid']		=$row['cityid'];
            $data['info']['three_cityid']=$row['three_cityid'];
            $data['info']['salary']		=$row['salary'];
            $data['info']['type']		=$row['type'];
            $data['info']['hits']		=$row['hits'];
            $data['info']['hy']		    =$row['hy'];
            $data['info']['report']		=$row['report'];
            $data['info']['job_classid']=$row['job_classid'];
            $data['info']['birthday']	=$row['birthday'];
            $data['info']['idcard_pic']	=$row['idcard_pic'];
            $data['info']['photo']	    =$row['photo'];
            $data['info']['resume_photo']=$row['resume_photo'];
            $data['info']['description']=preg_replace(array("/\r\n\r\n\r\n/"), array("\r\n"),strip_tags($description));
            $data['info']['address']	=$row['address'];
            $data['info']['integrity']	=$row['integrity'];
            $data['info']['jobstatus']	=$row['jobstatus'];
            $data['info']['avghour']	=$row['avghour'];
            //小程序所需汉字字段-start
            //名称显示处理
            if($this->config['user_name']=='1' || !$this->config['user_name']){
                if($row['nametype']=='1'){
                    $data['info']['name'] = $row['name'];
                }else if($row['nametype']=='2'){
                    $data['info']['name'] = "NO.".$row['id'];
                }else{
                    if($row['sex']==1){
                        $data['info']['name'] = mb_substr($row['name'],0,1,'utf-8')."先生";
                    }else{
                        $data['info']['name'] = mb_substr($row['name'],0,1,'utf-8')."女士";
                    }
                }
            }elseif($this->config['user_name']=='2'){
                $data['info']['name'] = "NO.".$row['id'];
            }elseif($this->config['user_name']=='3'){
                if($row['sex']==1){
                    $data['info']['name'] = mb_substr($row['name'],0,1,'utf-8')."先生";
                }else{
                    $data['info']['name'] = mb_substr($row['name'],0,1,'utf-8')."女士";
                }
            }elseif($this->config['user_name']=='4'){
                $data['info']['name'] = $row['name'];
            }
            
            if(!$data['info']['name']){
                $data['info']['name'] = $row['name'];
            }
            $data['info']['sex_n']      =$arr_data['sex'][$row['sex']];
            $data['info']['exp_n']      =$userclass_name[$row['exp']];
            $data['info']['edu_n']      =$userclass_name[$row['edu']];
            $data['info']['type_n']     =$userclass_name[$row['type']];
            $data['info']['report_n']   =$userclass_name[$row['report']];
            $data['info']['jobstatus_n']=$userclass_name[$row['jobstatus']];
            $data['info']['marriage_n'] =$userclass_name[$row['marriage']];
            $data['info']['hy_n']       =$industry_name[$row['hy']];
            $data['info']['lastupdate_n']=date("Y-m-d",$row['lastupdate']);
            if($row['telphone']||$row['telphone']||$row['email']||$row['idcard']||$row['qq']||$row['address']){
                $data['info']['islink']=1;
            }
            if($row['job_classid']){
                $job=@explode(',', $row['job_classid']);
                foreach($job as $val){
                    $jobn[]=$job_name[$val];
                }
                $data['info']['job_n']=@implode(',',$jobn);
            }
            if($row['city_classid']){
                $city=@explode(',', $row['city_classid']);
                foreach($city as $val){
                    $cityn[]=$city_name[$val];
                }
                $data['info']['city']=@implode(',',$cityn);
            }
            if ($row['minsalary']){
                if ($row['maxsalary']>0){
                    $data['info']['salary_n']="￥".$row['minsalary'].'-'.$row['maxsalary'];
                }else{
                    $data['info']['salary_n']="￥".$row['minsalary'].'以上';
                }
            }else{
                $data['info']['salary_n']='面议';
            }
            if ($row['tag']){
                $data['info']['tag_n']=@explode(',', $row['tag']);
            }
            if($row['photo']&& $row['phototype']!='1'&&(file_exists(str_replace('./',APP_PATH,$row['photo'])))){
                $data['info']['photo_n']=str_replace("./",$this->config['sy_weburl']."/",$row['photo']);
            }else{
                if($row['sex']==1){
                    $data['info']['photo_n']=$this->config['sy_weburl'].'/'.$this->config['sy_member_icon'];
                }else{
                    $data['info']['photo_n']=$this->config['sy_weburl'].'/'.$this->config['sy_member_iconv'];
                }
            }
            if($row['wxewm']&&(file_exists(str_replace('./',APP_PATH,$row['wxewm'])))){
                $data['info']['wxewm_n']=str_replace("./",$this->config['sy_weburl']."/",$row['wxewm']);
            }
            if($row['sex']==1){
                $data['info']['seximg']="/image/rnr.png";
            }else{
                $data['info']['seximg']="/image/rg.png";
            }
            
            //小程序所需汉字字段-end
            $ewhere="`eid`='".$row['id']."'";
            if($row['doc']==1){
                $doc = $this->obj->DB_select_once("resume_doc",$ewhere);
                $data['docbody']['id']=$doc['id'];
                $data['docbody']['body']=$doc['doc'];
            }else{
                //技能
                $skill = $this->obj->DB_select_all("resume_skill",$ewhere);
                if(is_array($skill)){
                    foreach($skill as $key=>$k){
                        $data['skill'][$key]['id']=$k['id'];
                        $data['skill'][$key]['name']=$k['name'];
                        $data['skill'][$key]['skill']=$k['skill'];
                        $data['skill'][$key]['ing']=$k['ing'];
                        $data['skill'][$key]['longtime']=$k['longtime'];
                        $data['skill'][$key]['pic']=str_replace("./",$this->config['sy_weburl']."/",$k['pic']);
                    }
                }
                //工作经历
                $work = $this->obj->DB_select_all("resume_work",$ewhere." order by sdate desc");
                if(is_array($work)){
                    foreach($work as $key=>$k){
                        $data['work'][$key]['id']=$k['id'];
                        $data['work'][$key]['name']=$k['name'];
                        $data['work'][$key]['sdate']=date("Y-m",$k['sdate']);
                        if ($k['edate']==0){
                            $data['work'][$key]['edate']="至今";
                        }else{
                            $data['work'][$key]['edate']=date("Y-m",$k['edate']);
                        }
                        $data['work'][$key]['department']=$k['department'];
                        $data['work'][$key]['title']=$k['title'];
                        $data['work'][$key]['content']=$k['content'];
                    }
                }
                
                //项目经历
                $project = $this->obj->DB_select_all("resume_project",$ewhere." order by sdate desc");
                if(is_array($project)){
                    foreach($project as $key=>$k){
                        $data['project'][$key]['id']=$k['id'];
                        $data['project'][$key]['name']=$k['name'];
                        $data['project'][$key]['sdate']=date("Y-m",$k['sdate']);
                        $data['project'][$key]['edate']=date("Y-m",$k['edate']);
                        $data['project'][$key]['title']=$k['title'];
                        $data['project'][$key]['content']=$k['content'];
                    }
                }
                //教育经历
                $edu = $this->obj->DB_select_all("resume_edu",$ewhere." order by sdate desc");
                if(is_array($edu)){
                    foreach($edu as $key=>$k){
                        $data['edu'][$key]['id']=$k['id'];
                        $data['edu'][$key]['name']=$k['name'];
                        $data['edu'][$key]['sdate']=date("Y-m",$k['sdate']);
                        $data['edu'][$key]['edate']=date("Y-m",$k['edate']);
                        $data['edu'][$key]['specialty']=$k['specialty'];
                        $data['edu'][$key]['title']=$k['title'];
                        $data['edu'][$key]['education']=$userclass_name[$k['education']];
                        $data['edu'][$key]['content']=$k['content'];
                    }
                }
                //培训经历
                $training = $this->obj->DB_select_all("resume_training",$ewhere." order by sdate desc");
                if(is_array($training)){
                    foreach($training as $key=>$k){
                        $data['training'][$key]['id']=$k['id'];
                        $data['training'][$key]['name']=$k['name'];
                        $data['training'][$key]['sdate']=date("Y-m",$k['sdate']);
                        $data['training'][$key]['edate']=date("Y-m",$k['edate']);
                        $data['training'][$key]['title']=$k['title'];
                        $data['training'][$key]['content']=$k['content'];
                    }
                }
                
                $other = $this->obj->DB_select_all("resume_other",$ewhere);
                if(is_array($other)){
                    foreach($other as $key=>$k){
                        $data['other'][$key]['id']=$k['id'];
                        $data['other'][$key]['name']=$k['name'];
                        $data['other'][$key]['content']=$k['content'];
                    }
                }
            }
            $data['error']=1;
        }else{
            $data['error']=2;
        }
        echo json_encode($data);die;
    }
    
    function joblist_action(){
        $comid=(int)$_POST['comid'];
        $joblist=$this->obj->DB_select_all('company_job',"uid=".$comid." and `status`<>1 and `state`='1'","id,name");
        $list=array('0'=>array('id'=>0,'name'=>'请选择职位'));
        if(is_array($joblist)){
            foreach ($joblist as $k=>$v){
                $list[$k+1]['id']=$v['id'];
                $list[$k+1]['name']=$v['name'];
            }
        }
        echo json_encode($list);die;
    }
    function inviteMsg_action(){
        $comid=(int)$_POST['comid'];
        $useridmsg=$this->obj->DB_select_once("userid_msg","`fid`='".$comid."' order by id desc");
        if ($useridmsg && is_array($useridmsg)){
            $data['linkman']=$useridmsg['linkman'];
            $data['linktel']=$useridmsg['linktel'];
            $data['intertime']=$useridmsg['intertime'];
            $data['address']=$useridmsg['address'];
            $data['content']=preg_replace(array("/\r\n\r\n\r\n/"), array("\r\n"),strip_tags($useridmsg['content']));
        }else{
            $com=$this->obj->DB_select_once("company","`uid`='".$comid."'","linkman,linktel,address");
            $data['linkman']=$com['linkman'];
            $data['linktel']=$com['linktel'];
            $data['address']=$com['address'];
        }
        echo json_encode($data);die;
    }
    function invite_action(){//邀请面试
        if(!$_POST['fid']||!$_POST['uid']||!$_POST['usertype']){
            $data['error']=3;//参数不正确
            echo json_encode($data);die;
        }
        
        /**验证权限**/
        //$this->CheckAppUser();
        /**验证权限结束**/
        $fid=(int)$_POST['fid'];
        $uid=(int)$_POST['uid'];
        $usertype=intval($_POST['usertype']);
        
        if($usertype!=2){
            $data['error']=2;//您不是企业用户
            $data['errmsg']='您不是企业用户';
            echo json_encode($data);die;
        }
        $joblist=$this->obj->DB_select_all('company_job',"uid=".$fid." and `status`<>1 and `state`='1'","id");
        if(!$joblist){
            $data['error']=3;
            $data['errmsg']='请发布职位后再邀请';
            echo json_encode($data);die;
        }
        $isblackname=$this->obj->DB_select_once("blacklist","`p_uid`='".$uid."' and `c_uid`='".$fid."' and `usertype`='1'");
        if(is_array($isblackname)){
            $data['error']=4;//您在该用户黑名单中，不能邀请
            $data['errmsg']='您在该用户黑名单中，不能邀请';
            echo json_encode($data);die;
        }
        if ($_POST['jobid']>0){
            $jobid=(int)$_POST['jobid'];
            $msgwhere="`uid`='".$uid."' AND `fid`='".$fid."' and `jobid`='".$jobid."'";
        }else{
            $msgwhere="`uid`='".$uid."' AND `fid`='".$fid."'";
        }
        $umessage = $this->obj->DB_select_once("userid_msg",$msgwhere);
        if(is_array($umessage)){
            $data['error']=5;//已邀请
            $data['errmsg']='您已邀请过该人才面试';
        }else{
            $row=$this->obj->DB_select_once("company_statis","`uid`='".$fid."'");
            if($row['rating']==0){
                //使用积分模式
                if($row['integral']<$this->config['integral_interview']*$this->config['integral_proportion'] && $this->config['integral_interview_type']=="2"){
                    $data['error']=6;
                    $data['errmsg']='您的积分不足，无法邀请';
                }else{//积分充足
                    $data['error']=1;
                    $data['integral']=$this->config['integral_interview']*$this->config['integral_proportion'];
                }
            }else{
                if($row['vip_etime']>time() || $row['vip_etime']==0){
                    if($row['rating_type']=="1"){
                        if($row['invite_resume']==0){//收费会员邀请简历已用完
                            if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//积分模式
                                if($row['integral']<$this->config['integral_interview']*$this->config['integral_proportion'] && $this->config['integral_interview_type']=="2"){
                                    $data['error']=6;//积分不足
                                    $data['errmsg']='您的积分不足，无法邀请';
                                }else{//积分充足
                                    $data['error']=7;
                                    $data['integral']=$this->config['integral_interview']*$this->config['integral_proportion'];
                                    $data['integral_pricename']=$this->config['integral_pricename'];
                                }
                            }else{
                                $data['error']=8;
                                $data['errmsg']='您的邀请数量已用完，无法邀请';
                            }
                        }else{
                            $data['error']=1;
                        }
                    }else{//时间模式
                        $data['error']=1;
                    }
                }else{
                    if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//积分模式
                        if($row['integral']<$this->config['integral_interview']*$this->config['integral_proportion'] && $this->config['integral_interview_type']=="2"){
                            $data['error']=6;//积分不足
                            $data['errmsg']='您的积分不足，无法邀请';
                        }else{//积分充足
                            $data['error']=7;
                            $data['integral']=$this->config['integral_interview']*$this->config['integral_proportion'];
                            $data['integral_pricename']=$this->config['integral_pricename'];
                        }
                    }else{
                        $data['error']=8;
                        $data['errmsg']='您的套餐已过期，无法邀请';
                    }
                }
            }
        }
        echo json_encode($data);die;
    }
    function invitesave_action(){
        if(!$_POST['fid']||!$_POST['uid']||!$_POST['usertype']){
            $data['error']=3;//参数不正确
            echo json_encode($data);die;
        }
        
        /**验证权限**/
        //$this->CheckAppUser();
        /**验证权限结束**/
        $fid=(int)$_POST['fid'];
        $uid=(int)$_POST['uid'];
        $usertype=intval($_POST['usertype']);
        $jobid=(int)$_POST['jobid'];
        $resume=$this->obj->DB_select_once("resume","`uid`='".$uid."'",'`name`,`def_job`');
        $username=$resume['name'];
        
        if($usertype!=2){
            $data['error']=4;//您不是企业用户
            $data['errmsg']='您不是企业用户';
            echo json_encode($data);die;
        }
        $isblackname=$this->obj->DB_select_once("blacklist","`p_uid`='".$uid."' and `c_uid`='".$fid."' and `usertype`='1'");
        if(is_array($isblackname)){
            $data['error']=2;//您在该用户黑名单中，不能邀请
            $data['errmsg']='您在该用户黑名单中，不能邀请';
            echo json_encode($data);die;
        }
        if ($jobid>0){
            $msgwhere="`uid`='".$uid."' AND `fid`='".$fid."' and `jobid`='".$jobid."'";
        }else{
            $msgwhere="`uid`='".$uid."' AND `fid`='".$fid."'";
        }
        $umessage = $this->obj->DB_select_once("userid_msg",$msgwhere);
        if(is_array($umessage)){
            $data['error']=6;//已邀请
            $data['errmsg']='您已邀请过该人才面试';
        }else{
            //判断当天是否已达到最大下载简历次数
            $companyM=$this->MODEL('company');
            $result = $companyM->comVipDayActionCheck('interview',$fid);
            if($result['status']!=1){
                $this->errjson($result['msg'],9);
            }
            
            $job=$this->obj->DB_select_once("company_job","`id`='".$jobid."'","`name`,`com_name`");
            $sql=array();
            $sql['title']    ='面试邀请';
            $sql['content']  =$this->stringfilter($_POST['content']);
            $sql['uid']      =$uid;
            $sql['fid']      =$fid;
            $sql['datetime'] =mktime();
            $sql['address']  =$_POST['address'];
            $sql['intertime']=$_POST['intertime'];
            $sql['linkman']  =$_POST['linkman'];
            $sql['linktel']  =$_POST['linktel'];
            $sql['jobid']    =$jobid;
            $sql['jobname']  =$job['name'];
            $sql['fname']    =$job['com_name'];
            $row=$this->obj->DB_select_once("company_statis","`uid`='".$fid."'");
            if($row['rating']==0){
                //使用积分模式
                if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//积分模式
                    if($row['integral']<$this->config['integral_interview']*$this->config['integral_proportion'] && $this->config['integral_interview_type']=="2"){
                        $data['error']=6;//积分不足
                        $data['errmsg']='您的积分不足，无法邀请';
                    }else{//积分充足
                        $this->obj->insert_into("userid_msg",$sql);
                        if($this->config['integral_interview_type']=="1"){//加积分
                            $auto=true;
                        }else{
                            $auto=false;
                        }
                        $this->MODEL('integral')->company_invtal($fid,$this->config["integral_interview"],false,"邀请会员面试");//积分操作记录
                        //$data['status']=1;
                        $data['error']=1;
                    }
                }else{
                    $data['error']=8;
                    $data['errmsg']='您的邀请数量已用完，无法邀请';
                }
            }else{
                if($row['vip_etime']>time() || $row['vip_etime']==0){
                    if($row['rating_type']=="1"){
                        if($row['invite_resume']==0){//收费会员邀请简历已用完
                            if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//积分模式
                                if($row['integral']<$this->config['integral_interview']*$this->config['integral_proportion'] && $this->config['integral_interview_type']=="2"){
                                    $data['error']=6;//积分不足
                                    $data['errmsg']='您的积分不足，无法邀请';
                                }else{//积分充足
                                    $this->obj->insert_into("userid_msg",$sql);
                                    if($this->config['integral_interview_type']=="2"){
                                        $auto=false;
                                    }else{
                                        $auto=true;
                                    }
                                    $this->MODEL('integral')->company_invtal($fid,$this->config['integral_interview']*$this->config['integral_proportion'],$auto,"邀请会员面试");//积分操作记录
                                    //$data['status']=1;
                                    $data['error']=1;
                                }
                            }else{
                                $data['error']=8;
                                $data['errmsg']='您的套餐已过期，无法邀请';
                            }
                        }else{
                            //收费会员简历没有用完的状态,直接邀请
                            $this->obj->insert_into("userid_msg",$sql);
                            $this->obj->DB_update_all("company_statis","`invite_resume`=`invite_resume`-1","`uid`='".$fid."'");
                            //$data['status']=1;
                            $data['error']=1;
                        }
                    }else{//时间模式
                        $this->obj->insert_into("userid_msg",$sql);
                        //$data['status']=1;
                        $data['error']=1;
                    }
                }else{
                    if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//积分模式
                        if($row['integral']<$this->config['integral_interview']*$this->config['integral_proportion'] && $this->config['integral_interview_type']=="2"){
                            $data['error']=6;//积分不足
                            $data['errmsg']='您的积分不足，无法邀请';
                        }else{//积分充足
                            $this->obj->insert_into("userid_msg",$sql);
                            if($this->config['integral_interview_type']=="2"){
                                $auto=false;
                            }else{
                                $auto=true;
                            }
                            $this->MODEL('integral')->company_invtal($fid,$this->config['integral_interview']*$this->config['integral_proportion'],$auto,"邀请会员面试");//积分操作记录
                            //$data['status']=1;
                            $data['error']=1;
                        }
                    }else{
                        $data['error']=8;
                        $data['errmsg']='您的套餐已过期，无法邀请';
                    }
                }
            }
            if ($data['error']==1){
                $this->member_log('在小程序邀请人才《'.$resume['name'].'》', $fid, $usertype);
                $this->msg_post($uid,$fid,array('username'=>$username,'jobname'=>$job['name']));
                $state_content = "我刚邀请了人才 <a href=\"".Url('resume',array("c"=>"show","id"=>$resume['def_job']))."\" target=\"_blank\">".$resume['name']."</a> 面试。";
                $this->addstate($state_content,1,$fid);//保存动态
                //推送
                $push = $this->getPush();
                if ($push){
                    $content = mb_substr($job['com_name'].'邀请您参加面试', 0, 24, 'UTF-8');
                    $this->makePush($job['com_name'], $content, array('uid'=>$uid), $push);
                }
            }
        }
        echo json_encode($data);die;
    }
    //邀请面试发送邮件手机短信
    function msg_post($uid,$comid,$info=array()){
        $com=$this->obj->DB_select_once("company","`uid`='$comid'");
        $uid=$this->obj->DB_select_once("member","`uid`='$uid'","email,moblie");
        $data=array();
        $data['type']="yqms";
        $data['username']=$info['username'];
        $data['jobname']=$info['jobname'];
        $data['company']=$com['name'];
        $data['linkman']=$com['linkman'];
        $data['comtel']=$com['linktel'];
        $data['comemail']=$com['linkmail'];
        $data['email']=$uid['email'];
        $data['moblie']=$uid['moblie'];
        $notice = $this->MODEL('notice');
        $notice->sendEmailType($data);
        $notice->sendSMSType($data);
    }
    function down_action(){//下载简历
        if(!$_POST['comid']||!$_POST['eid']||!$_POST['uid']){
            $data['error']=3;//参数不正确
            $data['errmsg']="参数不正确";
            echo json_encode($data);die;
        }
        $eid=(int)$_POST['eid'];
        $comid=(int)$_POST['comid'];
        $uid=(int)$_POST['uid'];
        $usertype=(int)$_POST['usertype'];
        if ($usertype==2){
            //企业用户，账号不是审核通过状态
            $member = $this->obj->DB_select_once("member","`uid`='".$comid."'","`status`");
            if($member['status'] != 1){
                $data['error']=8;
                $data['errmsg']="您的帐号未通过审核";
                echo json_encode($data);die;
            }
            if ($this->config['com_lietou_job']=='1'){
                //企业发布职位才能下载简历
                if($comid>0){
                    $Job=$this->MODEL("job");
                    $list=$Job->GetComjobList(array("uid"=>$comid,"state"=>1,'r_status<>'=>2,'status<>'=>1),array("field"=>"`id`"));
                    if(!$list){
                        $data['error']=2;
                        $data['errmsg']="还未发布职位,无法查看联系方式";
                        echo json_encode($data);die;
                    }
                }
            }
            $black=$this->obj->DB_select_once("blacklist","`c_uid`='".$uid."' and `p_uid`='".$comid."'");
            if(!empty($black)){
                $data['error']=4;
                $data['errmsg']="您已被该用户列入黑名单";
                echo json_encode($data);die;
            }
            
            $info=$this->obj->DB_select_once("down_resume","`eid`='".$eid."' and `comid`='".$comid."'");
            if(is_array($info) && !empty($info)){
                $data['error']=1;//已下载
            }else{
                //判断当天是否已达到最大下载简历次数
                $companyM=$this->MODEL('company');
                $result = $companyM->comVipDayActionCheck('resume',$comid);
                if($result['status']!=1){
                    $this->errjson($result['msg'],9);
                }
                
                $sql="eid='".$eid."',";
                $sql.="uid='".$uid."',";
                $sql.="comid='".$comid."',";
                $sql.="downtime='".time()."'";
                
                $row=$this->obj->DB_select_once("company_statis","`uid`='".$comid."'","vip_etime,down_resume,rating_type,integral");
                if($row['vip_etime']>time() || $row['vip_etime']==0){
                    if($row['rating_type']=="2"){//时间模式
                        $this->obj->DB_insert_once("down_resume",$sql);
                        $data['error']=1;
                    }elseif($row['down_resume']>0){//收费会员下载简历数
                        $this->obj->DB_insert_once("down_resume",$sql);
                        $this->obj->DB_update_all("company_statis","`down_resume`=`down_resume`-1","uid='".$comid."'");
                        $data['error']=1;
                    }else{
                        if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//使用积分模式
                            if($row['integral']<$this->config['integral_down_resume']*$this->config['integral_proportion'] && $this->config['integral_down_resume_type']=="2"){
                                $data['error']=5;
                                $data['errmsg']="积分不足";
                            }else{//积分充足
                                $data['error']=6;
                                $data['integral']=$this->config['integral_down_resume']*$this->config['integral_proportion'];
                                $data['integral_pricename']=$this->config['integral_pricename'];
                            }
                        }elseif($this->config['com_integral_online']=="2"){
                            $data['error']=8;
                            $data['integral']=$this->config['integral_down_resume'];
                        }else{
                            $data['error']=7;
                            $data['errmsg']="您的下载简历数已用完";
                        }
                    }
                    if ($data['error']==1){
                        $this->obj->DB_update_all("company_statis","`down_resume`=`down_resume`-1","`uid`='".$uid."'");
                        $user=$this->obj->DB_select_once("resume_expect","id=".$eid."",'uname');
                        $this->member_log('在小程序下载简历《'.$user['uname'].'》', $comid, $usertype);
                        $state_content = "新下载了简历 <a href=\"".Url("wap",array('c'=>'resume','a'=>'show','id'=>$eid))."\" target=\"_blank\">".$user['uname']."</a> 。";
                        $this->addstate($state_content,2,$comid);//保存动态
                    }
                }else{
                    if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="3"){//使用积分模式
                        if($row['integral']<$this->config['integral_down_resume']*$this->config['integral_proportion'] && $this->config['integral_down_resume_type']=="2"){
                            $data['error']=5;
                            $data['errmsg']="积分不足";
                        }else{//积分充足
                            $data['error']=6;
                            $data['integral']=$this->config['integral_down_resume']*$this->config['integral_proportion'];
                            $data['integral_pricename']=$this->config['integral_pricename'];
                        }
                    }elseif($this->config['com_integral_online']=="2"){
                        $data['error']=8;
                        $data['integral']=$this->config['integral_down_resume'];
                    }else{
                        $data['error']=7;
                        $data['errmsg']="您的下载简历数已用完";
                    }
                }
            }
        }
        echo json_encode($data);die;
    }
    function downresume_action(){
        if(!$_POST['comid']||!$_POST['eid']||!$_POST['uid']){
            $data['error']=3;//参数不正确
            $data['errmsg']="参数不正确";
            echo json_encode($data);die;
        }
        $eid=(int)$_POST['eid'];
        $comid=(int)$_POST['comid'];
        $uid=(int)$_POST['uid'];
        $usertype=(int)$_POST['usertype'];
        if ($usertype==2){
            if ($this->config['com_lietou_job']=='1'){
                //企业发布职位才能下载简历
                if($comid>0){
                    $Job=$this->MODEL("job");
                    $list=$Job->GetComjobList(array("uid"=>$comid,"state"=>1,"`edate`>'".time()."' and `r_status`<>'2' and `status`<>'1'"),array("field"=>"`id`"));
                    if(empty($list)){
                        $data['error']=2;
                        $data['errmsg']="还未发布职位,无法查看联系方式";
                    }
                }
            }
            $black=$this->obj->DB_select_once("blacklist","`c_uid`='".$uid."' and `p_uid`='".$comid."'");
            if(!empty($black)){
                $data['error']=4;
                $data['errmsg']="您已被该用户列入黑名单";
            }
            
            $info=$this->obj->DB_select_once("down_resume","`eid`='".$eid."' and `comid`='".$comid."'");
            if(is_array($info) && !empty($info)){
                $data['error']=8;//已下载
            }else{
                /**验证权限**/
                //$_POST = $this->CheckAppUser();
                /**验证权限结束**/
                $sql="eid='".$eid."',";
                $sql.="uid='".$uid."',";
                $sql.="comid='".$comid."',";
                $sql.="downtime='".time()."'";
                $row=$this->obj->DB_select_once("company_statis","`uid`='".$comid."'","vip_etime,down_resume,rating_type,integral");
                if($row['vip_etime']>time() || $row['vip_etime']==0){
                    if($row['rating_type']=="2"){//时间模式
                        $this->obj->DB_insert_once("down_resume",$sql);
                        $data['error']=1;
                    }elseif($row['down_resume']>0){//收费会员下载简历数
                        $this->obj->DB_insert_once("down_resume",$sql);
                        $this->obj->DB_update_all("company_statis","`down_resume`=`down_resume`-1","uid='".$comid."'");
                        $data['error']=1;
                    }else{
                        if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="1"){//使用积分模式
                            if($row['integral']<$this->config['integral_down_resume']*$this->config['integral_proportion'] && $this->config['integral_down_resume_type']=="2"){
                                $data['error']=5;
                                $data['errmsg']="积分不足";
                            }else{//积分充足
                                $this->obj->DB_insert_once("down_resume",$sql);
                                if($this->config['integral_down_resume_type']=="2"){
                                    $auto=false;
                                }else{
                                    $auto=true;
                                }
                                $this->MODEL('integral')->company_invtal($comid,$this->config['integral_down_resume']*$this->config['integral_proportion'],$auto,"下载简历");//积分操作记录
                                $data['error']=1;
                            }
                        }else{
                            $data['error']=7;
                            $data['errmsg']="您的下载简历数已用完";
                        }
                    }
                }else{
                    if($this->config['com_integral_online']=="1" || $this->config['com_integral_online']=="1"){//使用积分模式
                        if($row['integral']<$this->config['integral_down_resume']*$this->config['integral_proportion'] && $this->config['integral_down_resume_type']=="2"){
                            $data['error']=5;
                            $data['errmsg']="积分不足";
                        }else{//积分充足
                            $this->obj->DB_insert_once("down_resume",$sql);
                            if($this->config['integral_down_resume_type']=="2"){
                                $auto=false;
                            }else{
                                $auto=true;
                            }
                            $this->MODEL('integral')->company_invtal($comid,$this->config['integral_down_resume']*$this->config['integral_proportion'],$auto,"下载简历");//积分操作记录
                            $data['error']=1;
                        }
                    }else{
                        $data['error']=7;
                        $data['errmsg']="您的下载简历数已用完";
                    }
                }
                if ($data['error']==1){
                    $this->obj->DB_update_all("company_statis","`down_resume`=`down_resume`-1","`uid`='".$uid."'");
                    $user=$this->obj->DB_select_once("resume_expect","id=".$eid."",'uname');
                    $this->member_log('在小程序下载简历《'.$user['uname'].'》', $comid, $usertype);
                    $state_content = "新下载了简历 <a href=\"".Url("wap",array('c'=>'resume','a'=>'show','id'=>$eid))."\" target=\"_blank\">".$user['uname']."</a> 。";
                    $this->addstate($state_content,2,$comid);//保存动态
                }
            }
        }
        echo json_encode($data);die;
    }
    
    function talent_pool_action(){
        $usertype=intval($_POST['usertype']);
        $uid=intval($_POST['cuid']);
        if($usertype!=2){
            $data['error']=4;//您不是企业用户
            echo json_encode($data);die;
        }else{
            /**验证权限**/
            //$_POST = $this->CheckAppUser();
            /**验证权限结束**/
            
            $row=$this->obj->DB_select_once("talent_pool","`cuid`='".$uid."' and `eid`='".(int)$_POST['eid']."'");
            if(!empty($row)){
                $data['error']=5;//已收藏
                echo json_encode($data);die;
            }else{
                $value=array(
                    'cuid'=>$uid,
                    'uid'=>(int)$_POST['uid'],
                    'eid'=>(int)$_POST['eid'],
                    'ctime'=>time()
                );
                $nid=$this->obj->insert_into("talent_pool",$value);
                if($nid){
                    $this->member_log("收藏简历 ".$value['job_name'], $uid, 2,5,1);
                    $data['error']=1;//成功
                }else{
                    $data['error']=2;
                }
                echo json_encode($data);die;
            }
        }
    }
    
}
?>